package com.liuche.book.auth.controller;

import com.liuche.book.auth.alarm.AlarmInterface;
import com.liuche.book.auth.model.vo.user.req.UpdatePasswordReqVO;
import com.liuche.book.auth.model.vo.user.req.UserLoginReqVO;
import com.liuche.book.auth.service.UserService;
import com.liuche.framework.biz.context.holder.UserContextHolder;
import com.liuche.framework.biz.operationlog.aspect.ApiOperationLog;
import com.liuche.framework.common.response.Response;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.*;

/**
 * 用户相关 controller
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @Resource(type = AlarmInterface.class)
    private AlarmInterface alarmInterface;

    @Resource(name = "taskExecutor")
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;

    /**
     * 用户登录或者注册接口
     * @param vo
     * @return
     */
    @PostMapping("/login")
    @ApiOperationLog(description = "用户登录/注册")
    public Response<String> login(@RequestBody UserLoginReqVO vo) {
        log.info("用户登录信息：【{}】", vo);
        return userService.login(vo);
    }

    /**
     * 退出登录接口
     * @return
     */
    @PostMapping("/logout")
    @ApiOperationLog(description = "账号登出")
    public Response<?> logout() {
        return userService.logout();
    }

    @PostMapping("/password/update")
    @ApiOperationLog(description = "用户修改密码")
    public Response<?> updatePWd(@RequestBody UpdatePasswordReqVO vo) {
        return userService.updatePwd(vo);
    }

    @GetMapping("/test")
    public String test() {
        alarmInterface.send();
        log.info("测试过滤器->【{}】", UserContextHolder.getUserId());
        return "这是一个test";
    }
}
